/*
 * @Descripttion: 
 * @Author: voanit
 * @Date: 2022-09-09 11:22:53
 * @LastEditors: voanit
 * @LastEditTime: 2022-09-11 16:48:58
 */
import { ref } from "vue";
import { useIntersectionObserver } from "@vueuse/core";

export const useLazyData = (callback: () => void) => {
  const target = ref(null)
  const { stop } = useIntersectionObserver(
    target,
    ([{ isIntersecting }], observerElement) => {
      if (isIntersecting) {
        stop(); /*只要第一次进入就关闭观察者  */
        callback && callback()
        // callback?.()
      }
    },
    {
      threshold: 0
    }
  );

  return target
}